package com.xueyu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.xueyu.model.User;
/**
 * 用户DAO
 * @author xueyu
 *
 */
public class UserDao {
	/**
	 * 用户登录֤
	 * @param con
	 * @param user
	 * @return User实体
	 * @throws Exception
	 */
		public  User LogOn(Connection con,User user) throws Exception{
			User resultUser = null;
			String sql = "select * from t_user where userName = ? and password = ?";
			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setString(1, user.getUserName());
			pstmt.setString(2, user.getPassword());
			ResultSet rs = pstmt.executeQuery();
			if(rs.next()){
				resultUser = new User();
				resultUser.setId(rs.getInt("userId"));
				resultUser.setUserName(rs.getString("userName"));
				resultUser.setPassword(rs.getString("Password"));
			}
			return resultUser;			
		}
}
